package com.youbug.mall.coupon_sms.service.impl;

import com.youbug.mall.coupon_sms.entity.SmsSeckillPromotion;
import com.youbug.mall.coupon_sms.mapper.SmsSeckillPromotionMapper;
import com.youbug.mall.coupon_sms.service.ISmsSeckillPromotionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.youbug.mall.coupon_sms.entity.SmsSeckillPromotion;
import org.springframework.util.ObjectUtils;
import com.youbug.common.vo.QueryVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.StringUtils;
import org.springframework.util.ObjectUtils;

/**
 * <p>
 * 秒杀活动 服务实现类
 * </p>
 *
 * @author youbug
 * @since 2024-07-20
 */
@Service
public class SmsSeckillPromotionServiceImpl extends ServiceImpl<SmsSeckillPromotionMapper, SmsSeckillPromotion> implements ISmsSeckillPromotionService {

        @Override
        public IPage<SmsSeckillPromotion> getSmsSeckillPromotionPage(QueryVo<SmsSeckillPromotion> queryVo) {

        Page<SmsSeckillPromotion> paramPage = new Page<>();

        paramPage.setCurrent(queryVo.getCurrentPage());

        paramPage.setSize(queryVo.getPageSize());

        QueryWrapper<SmsSeckillPromotion> wrapper = new QueryWrapper<>();

        SmsSeckillPromotion smsSeckillPromotion = queryVo.getPayload();

        if(!ObjectUtils.isEmpty(smsSeckillPromotion)){
            if(smsSeckillPromotion.getId()!=null){
            wrapper.eq("id", smsSeckillPromotion.getId());
            }
            if(StringUtils.hasText(smsSeckillPromotion.getTitle())){
                wrapper.eq("title", smsSeckillPromotion.getTitle());
            }
            if(!ObjectUtils.isEmpty(smsSeckillPromotion.getStartTime())){
                wrapper.gt("start_time", smsSeckillPromotion.getStartTime());
            }
            if(!ObjectUtils.isEmpty(smsSeckillPromotion.getEndTime())){
                wrapper.gt("end_time", smsSeckillPromotion.getEndTime());
            }
            if(smsSeckillPromotion.getStatus()!=null){
            wrapper.eq("status", smsSeckillPromotion.getStatus());
            }
            if(smsSeckillPromotion.getUserId()!=null){
            wrapper.eq("user_id", smsSeckillPromotion.getUserId());
            }
        }
        if(!ObjectUtils.isEmpty(queryVo.getStartTime())){
            wrapper.gt("create_time", queryVo.getStartTime());
        }
        if(!ObjectUtils.isEmpty(queryVo.getEndTime())){
            wrapper.lt("create_time", queryVo.getEndTime());
        }
        wrapper.orderByDesc("create_time");

        Page<SmsSeckillPromotion> page = this.page(paramPage, wrapper);

        return page;
        }

       /* @Transactional(transactionManager = "transactionManagerXXX", rollbackFor = Exception.class)
        public boolean saveBatch(Collection<SmsSeckillPromotion> entityList) {
        return saveBatch(entityList, DEFAULT_BATCH_SIZE);
        }
        */
}
